<%@ include file="/WEB-INF/views/includes/include.jsp" %>
  
   
<table border="0" width="100%">	
 <tr>
  <td>
                                           
                                                     
<div id="mamount0" style="border:0; color:#f6931f; font-weight:bold;" />
</div>
<div id="mselector0"></div>
<br>

<div id="mamount1" style="border:0; color:#f6931f; font-weight:bold;" />
</div>
<div id="mselector1"></div>
<br>

<div id="mamount2" style="border:0; color:#f6931f; font-weight:bold;" />
</div>
<div id="mselector2"></div>
<br>

<div id="mamount3" style="border:0; color:#f6931f; font-weight:bold;" />
</div>
<div id="mselector3"></div>
<br>

<div id="mamount4" style="border:0; color:#f6931f; font-weight:bold;" />
</div>
<div id="mselector4"></div>
<br>

<div id="mamount5" style="border:0; color:#f6931f; font-weight:bold;" />
</div>
<div id="mselector5"></div>
<br>
											
                                        </td>
                                    </tr>
									<tr>
                                        <td>
                                            <span class="genbutton" id="addDep">Deploy Army</span>
                                        </td>
                                    </tr>
                                </table>


    
<script language="javascript">
function arrayCount(arr) {
	var count = 0
	for (var i in arr)
	{
		 count++
	}
	return count
	}

function resetArray(arr)
{
	 if(len<1)
		  for(var i=0;i<6;i++)
		  {
			arr[i]=0;  
		  }
}
var locid=${dep};

var vals = new Array(20);
var usedvals = new Array(20);
var maxvalue= new Array(20);
var i;
<c:forEach items="${engagement}" var="eng">
i=parseInt(${eng.key});
vals[i]=<c:out value="${eng.value}"/>;
 </c:forEach>

 <c:forEach items="${usedResources}" var="usedup">
 i=parseInt(${usedup.key});
 usedvals[i]=<c:out value="${usedup.value}"/>;
  </c:forEach>

  var len=arrayCount(vals);
  if(len<5) resetArray(vals);

  len=arrayCount(usedvals);
  if(len<5) resetArray(usedvals);

 for(var m=0;m<6;m++)
 {
	 maxvalue[m]=(mresources[m]-usedvals[m])+vals[m];
 }
 
  
$('#addDep').button();

$(function() {
		
		$("#mselector0").slider({
			value:vals[0],
			min: 0,
			max: maxvalue[0],
			animate: true,
			slide: function(event, ui) {
				$("#mamount0").html('Army: ' + ui.value + " / Free: " + (maxvalue[0]-ui.value));
			}
		});
		$("#mamount0").html('Army: ' + $("#mselector0").slider("value")+ " / Free: " + (maxvalue[0]-$("#mselector0").slider("value")));

	$("#mselector1").slider({
			value:vals[1],
			min: 0,
			max: maxvalue[1],
			animate: true,
			slide: function(event, ui) {
				$("#mamount1").html('Tank: ' + ui.value + " / Free: " + (maxvalue[1]-ui.value));
			}
		});
		$("#mamount1").html('Tank: ' + $("#mselector1").slider("value") + " / Free: " + (maxvalue[1]-$("#mselector1").slider("value")));

	$("#mselector2").slider({
			value:vals[2],
			min: 0,
			max: maxvalue[2],
			animate: true,
			slide: function(event, ui) {
				$("#mamount2").html('Aircraft: ' + ui.value + " / Free: " + (maxvalue[2]-ui.value));
			}
		});
		$("#mamount2").html('Aircraft: ' + $("#mselector2").slider("value") + " / Free: " + (maxvalue[2]-$("#mselector2").slider("value")));

	$("#mselector3").slider({
			value:vals[3],
			min: 0,
			max: maxvalue[3],
			animate: true,
			slide: function(event, ui) {
				$("#mamount3").html('Navy: ' + ui.value + " / Free: " + (maxvalue[3]-ui.value));
			}
		});
		$("#mamount3").html('Navy: ' + $("#mselector3").slider("value") + " / Free: " + (maxvalue[3]-$("#mselector3").slider("value")));

	$("#mselector4").slider({
			value:vals[4],
			min: 0,
			max: maxvalue[4],
			animate: true,
			slide: function(event, ui) {
				$("#mamount4").html('Spies: ' + ui.value + " / Free: " + (maxvalue[4]-ui.value));
			}
		});
		$("#mamount4").html('Spies: ' + $("#mselector4").slider("value")+ " / Free: " + (maxvalue[0]-$("#mselector4").slider("value")));

	$("#mselector5").slider({
			value:vals[5],
			min: 0,
			max: maxvalue[5],
			animate: true,
			slide: function(event, ui) {
				$("#mamount5").html('Submarines: ' + ui.value + " / Free: " + (maxvalue[5]-ui.value));
			}
		});
		$("#mamount5").html('Submarines: ' + $("#mselector5").slider("value") + " / Free: " + (maxvalue[5]-$("#mselector5").slider("value")));


	});


$('#addDep').bind('click', function(event) {
	
	$.getJSON("deploy/addmydeployment", {
		locID:locid,
	    m0 : $("#mselector0").slider("value"),
	    m1 : $("#mselector1").slider("value"),
	    m2 : $("#mselector2").slider("value"),
	    m3 : $("#mselector3").slider("value"),
	    m4 : $("#mselector4").slider("value"),
	    m5 : $("#mselector5").slider("value")
	}, function(rtnmsg) {
		//FIXME check for invalid returns
		    jalert("Congratulations! You have successfully added the new location")

	    });

});


</script>
  

        